package copy.com;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**这玩意需要对应你实体的字段 有就给值 数量必须对的上否则直接报设置错误
 **/
@Component
public class MyMetaObjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //手动输入时间的优先级低于这里的处理
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("createUser",BaseContext.getCurrentId());
        metaObject.setValue("updateUser",BaseContext.getCurrentId());
        //不同的是 通过这种方法是取线程唯一标识 直接取出即可 不需要存
//        metaObject.setValue("createUser",Thread.currentThread().getId());
//        metaObject.setValue("updateUser",Thread.currentThread().getId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser",BaseContext.getCurrentId());

    }
}






